<?php
/**
 * Created by PhpStorm.
 * User: songs
 * Date: 2019/10/12
 * Time: 10:13
 */

namespace App\admin\TableView;


use App\admin\TableView\BaseClass\BaseViewList;
use App\Jobs\Fun;
use App\Models\Admin\ApilistModel;
use App\Models\Admin\CategoryModel;
use App\Models\Admin\CompanyModel;
use App\Models\Admin\JobModel;
use App\Models\Admin\OrderBaleModel;
use App\Models\Admin\OrderTempModel;
use App\Models\Admin\UserModel;
use App\Models\AreaModel;
use App\Models\JobsCompanysModel;
use App\Models\Main\AdModel;
use App\Models\NewsModel;
use Faker\Provider\Company;

class NewsListView extends BaseViewList
{

    public function get_model(){
        return new NewsModel();
    }

    public $show_add = false; ///显示添加按钮
    /**
     * 是否显示删除按钮
     */
    public $show_delete = false;
    public $topTitle = '资讯列表';
    public $PageSize = 10;

    public $breadcrumb = '<li><a href="/mcadmin">Home</a></li>
        <li><a href="javascript:;">资讯列表</a></li>
        ';

    public $html = '';


    //  public $show_add = false; ///显示添加按钮

    /**
     * 获取表格的唯一名字
     */
    public function getName()
    {
        return 'NewsModel';
    }


    /**
     * 需要继承,然后定义每行需要显示的数据格式
     */
    public function Labels()
    {
        return array(
            //   BaseViewList::Button_checkbox=>[],
            'id' => 50,
            'thumb' => 150,
            'cid' => 50,
            'title' => 100,
            'desc' => 100,
            'status' => 100,
            'praise' => 100,
            'pv' => 80,
            'created_at' => 150,
            'paixu' => 150,
            BaseViewList::Button_control => [
                BaseViewList::Button_Edit,
                BaseViewList::Button_Delete
            ]
        );
    }

    /**
     * 对话框中的各个字段
     */
    public function dialog()
    {
        return array(
            array(
                'title'=>'状态',
                'zd'=>'status',
                'type'=>'list',
                'data'=>NewsModel::getstatus()
            ),
            array(
                'title'=>'排序',
                'zd'=>'paixu',
                'type'=>self::dialog_number
            ),
        );
    }

    /**
     * 方便继承,多一层过滤
     */
    public function ModelTohtml($key, $model)
    {
        if($key==='created_at'){
            return Fun::date($model->$key);
        }
        if($key=='thumb'){
            return $this->toImg($model->$key);
        }
        if($key=='status'){
            return NewsModel::getstatus($model->$key);
        }
        return parent::ModelTohtml($key, $model);
    }

    /**
     * 返回查询的条件
     */
    public function find()
    {
        $find = $this->get_model()->where([
        ]);
        $id=$_GET['id']??'';
        if($id!==''){
            $find->where([
                'bale'=>$id
            ]);
        }
        $cid=$_GET['cid']??'';
        if($cid!==''){
            $find->where([
                'cid'=>$cid
            ]);
        }

        $find->orderBy('paixu', 'DESC');
        $find->orderBy('id', 'DESC');
        return $find;
    }


    /**
     * 顶部的选择区,参数,如果为空,则不显示选择器
     */
    public function getselectAttr()
    {

        /// self::dropDownList,
        $where = [

        ];
        return $where;
    }

}
